-- ==============================================
-- Basic Settings
-- ==============================================

-- Enable filetype detection
-- Enable automatic indentation
vim.cmd [[
  filetype on                       
  filetype indent on                
]]

local opt = vim.opt
local create_cmd = vim.api.nvim_create_autocmd

opt.tabstop = 4                  	-- Number of spaces for a tab
opt.shiftwidth = 4               	-- Number of spaces for autoindent
opt.showmatch = true             	-- Highlight matching parentheses
opt.autoindent = true            	-- Enable auto indentation
opt.cindent = true               	-- Enable C-style indentation
opt.hlsearch = true               	-- Highlight search matches

-- ==============================================
-- Statusline 
-- ==============================================
function statusline()
    local mode = vim.fn.mode()  
    local mode_text = {
        n = 'NORMAL',
        i = 'INSERT',
        v = 'VISUAL',
        V = 'V-LINE',
        ['\22'] = 'V-BLOCK', 	-- ctrl-v
        c = 'COMMAND',
        s = 'SELECT',
        t = 'TERMINAL',
    }

	-- Status Component
    local mode_display = mode_text[mode] or mode
	local filename = vim.fn.expand('%:t')
	local modified = vim.bo.modified and '[+]' or '[-]'
	local readonly = vim.bo.readonly and '[RO]' or '[RW]'

	local current_line = vim.fn.line('.')
	local current_col = vim.fn.col('.')
	local total_lines = vim.fn.line('$')
	local line_col = string.format(' [%d-%d:%d] ', current_line, total_lines, current_col)

	local file_encoding = string.upper(vim.api.nvim_buf_get_option(0, 'fileencoding'))

	-- Statusline Section 
	local left_section = string.format('<<< %s   <<< %s   <<< %s %s',
										mode_display, filename, modified, readonly)
	local right_section = string.format('<<< %s   <<< %s',
										file_encoding, line_col)

	return left_section .. '%=' .. right_section
end

opt.statusline = "%!v:lua.statusline()"
opt.laststatus = 2

-- ==============================================
-- Search 
-- ==============================================
opt.ignorecase = true            	-- Case insensitive search

-- ==============================================
-- Cursor 
-- ==============================================
opt.guicursor = 'n-v-c:block,i:block'
-- opt.cursorline = false 	-- Theme Nord will open it automatically

-- ==============================================
-- Line Numbers
-- ==============================================
opt.relativenumber = true        	-- Show relative line numbers
opt.number = true                 	-- Show absolute line numbers

-- ==============================================
-- Clipboard and Colors
-- ==============================================
opt.clipboard = 'unnamedplus'    	-- Use system clipboard
opt.termguicolors = true         	-- Enable true color support
opt.laststatus = 2                	-- Always show status line
opt.background = 'dark'          	-- Set background to dark
opt.cursorline = true             	-- Highlight the current line

-- ==============================================
-- Misc 
-- ==============================================
opt.updatetime = 300             	-- Delay for CursorHold events
opt.mouse = 'a'                  	-- Enable mouse support
-- opt.scrolloff = 4                 	-- Minimum number of lines to keep above/below cursor

-- ==============================================
-- Display command combinations 
-- ==============================================
opt.showcmd = false

-- ==============================================
-- End of Configuration
-- ==============================================
